#include <iostream>
using namespace std;

int main()
{
    int input, hundreds, decade, unit, sum = 0;
    bool finished = false;
    while(!finished)
    {
        sum = 0;
        cout << "Please input a number between 0 and 1000 here: ";
        cin >> input;

        if(input > 999)
        {
            cout << "Please enter a number less than 1000." << endl;
            continue;
        }

        if(input > 99)
        {
            hundreds = input / 100;
            cout << "hundreds = " << hundreds << endl;
            sum += hundreds;
        }

        if(input > 9)
        {
            decade = input / 10 % 10;
            cout << "decade = " << decade << endl;
            sum += decade;
        }

        unit = input % 10;
        cout << "unit = " << unit << endl;
        sum += unit;
        cout << "sum = " << sum << endl;
    }

    return 0;
}
